package com.qfedu.mall.api.controller;

import com.qfedu.mall.common.vo.ResultVO;
import com.qfedu.mall.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author dyw
 * @Date 2021年12月02日 11:16
 * qyxy.baic.cn
 */
@RestController
@CrossOrigin
@RequestMapping("/product")
@Api(value = "提供订单信息信息相关接口",tags = "订单管理")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/order")
    @ApiOperation("根据用户id、订单状态查询订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer",value = "用户ID",name = "userId",required = true),
            @ApiImplicitParam(dataType = "Integer",value = "订单状态，传空值为查看该用户所有id，1:待付款 2:待发货 3:待收货 4:待评价 5:已完成 6:已取消",name = "status",required = false)
    })
    public ResultVO orderInquiry(Integer userId,Integer status){

        System.out.println(userId);
        System.out.println(status);
        ResultVO resultVO = orderService.orderInquiry(userId,status);

        return resultVO;
    }


    /**
     * 立即购买
     */
    @PostMapping("/buyNow")
    @ApiOperation("立即购买")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "Integer",value = "商品Id",name = "productId",required = true),
            @ApiImplicitParam(dataType = "Integer",value = "用户ID",name = "userId",required = true),
            @ApiImplicitParam(dataType = "String",value = "商品规格",name = "goodsSize",required = true),
            @ApiImplicitParam(dataType = "Integer",value = "地址ID",name = "addrId",required = true),
            @ApiImplicitParam(dataType = "Integer",value = "商品数量",name = "productNum",required = true),
            @ApiImplicitParam(dataType = "Double",value = "总金额",name = "totalAmount",required = true),
            @ApiImplicitParam(dataType = "Double",value = "实际支付金额",name = "actualAmount",required = true),
            @ApiImplicitParam(dataType = "String",value = "备注",name = "remark",required = false),
    })
    public ResultVO BuyNow(Integer productId, Integer userId, String goodsSize, Integer addrId,
                           Integer productNum,Double totalAmount,Double actualAmount,String remark){

        System.out.println(productId);
        System.out.println(userId);
        System.out.println(goodsSize);
        System.out.println(addrId);
        System.out.println(productNum);
        System.out.println(totalAmount);
        System.out.println(actualAmount);
        System.out.println(remark);
        ResultVO resultVO = orderService.buyNow(productId, userId, goodsSize, addrId, productNum, totalAmount, actualAmount, remark);


        return resultVO;
    }



}
